#!/bin/bash
# BashChat by BiteTheByte [bitethebyte (at) gmail (dot) com]
# Licensed under GPLv3
# This program is written in bash scripting and comes with absolutely NO WARRANTY
# Be carefull and use it with "caution and wisdom".
# :) Enjoy ssh chatting!!!

#I like using useless variables as infinite looping condition. Yay ^.^
nosense=""
mesg=""
# $1 for chatroom history path $2 for room name separator $3 for message length.
#Checking for enough parameters
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ];
then
	echo "chat_pipe Error: Bad Parameters"
else
#Checking for existent history and pipe.
if [ -e "$1" ] && [ -e "$1$2""p"  ];
then
	while [ -z $nosense ]; do
	#Give to the pipe what is pipe's
 mesg=$(cat $1$2"p")
if (( $(echo "$mesg" | wc -m) < ($3 + 1) ));then
	echo "$mesg" >> "$1"
fi
	done
else
	echo "chat_pipe Error: Chatroom not exists"
fi
fi 
